{extend name="public/_home" /}

{block name='title'}管理员列表{/block}

{block name='main'}
<!-- Page Content -->
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li class="active">
                <i class="fa fa-home"></i>&nbsp;管理员管理
            </li>
            <li>管理员列表</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->
    <!-- Page Body -->
    <div class="page-body">
        <a href="{:url('admin/admin/add')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;管理员添加</a>
        <div class="row">
            <div class="col-xs-12">
                <div class="widget">
                    <div class="widget-header">
                        <span class="widget-caption">管理员列表</span>
                        <div class="widget-buttons">
                            {$admins|raw|replace}
                        </div>
                    </div>
                    <div class="widget-body">
                        <table class="table table-hover table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>账号</th>
                                <th>昵称</th>
                                <th>邮箱</th>
                                <th>状态</th>
                                <th>权限</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="admins" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.nickname}</td>
                                <td>{$vo.email}</td>
                                <td>{$vo.status ? '正常' : '禁用'}</td>
                                <td>{$vo.is_super ? '超级管理员' : '普通管理员'}</td>
                                <td>
                                    {if (session('admin.is_super') && $vo.is_super != 1)}
                                    <a href="#" class="btn btn-xs adminIs {$vo.status?'btn-darkorange':'btn-success'}"
                                       data-id="{$vo.id}" data-status="{$vo.status}">{$vo.status?'禁用':'启用'}</a>
                                    {/if}
                                    <a href="{:url('admin/admin/edit?id='.$vo.id)}" class="btn btn-azure btn-xs">编辑</a>
                                    <a href="#" class="btn btn-danger btn-xs cate-del" dataid="{$vo.id}">删除</a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /Page Body -->
</div>
<!-- /Page Content -->
{/block}
{block name='js'}
<script>
    $('.adminIs').click(function () {
        let id = $(this).data('id');
        let status = $(this).data('status');
        let msg = status ? "禁用" : "启用";
        layer.confirm(`确定${msg}?`, {
            title: "状态操作",
            icon: 3,
            amount: 6
        }, function () {
            layer.close();
            $.ajax({
                url: "{:url('admin/admin/status')}",
                type: "post",
                data: {id, status},
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            location.href = data.url
                        })
                    } else {
                        layer.open({
                            title: "操作失败",
                            icon: 5,
                            content: data.msg
                        })
                    }
                }
            })
        });
        return false;
    });
</script>
{/block}